package terra.model.visual;

import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.Renderable;

import terra.Config;
import terra.managers.LightManager;
import terra.model.GameObject;
import terra.slick.GameState;

public class LRImageVisualizator extends AbstractVisualizator
{
	public transient Renderable render2;
	
	@Override
	public void draw(Graphics g, GameObject object, float x, float y)
	{
		if (blend)
		{			
			int x1 = GameState.getInstance().getTiledOffsetX()-4;
			int y1 = GameState.getInstance().getTiledOffsetY()-4;
			if (object.isLeft())
				LightManager.getInstance().blend((int)(object.getX()/Config.tileSize-x1),(int)(object.getY()/Config.tileSize-y1),(Image) render2);
			else
				LightManager.getInstance().blend((int)(object.getX()/Config.tileSize-x1),(int)(object.getY()/Config.tileSize-y1),(Image) render);
			if (width == -1 ||  height == -1)
			{
				if (object.isLeft())
					((Image) render2).draw(x, y);
				else
					((Image) render).draw(x, y);
			}
			else
			{
				if (object.isLeft())
					((Image) render2).draw(x, y,width,height);
				else
					((Image) render).draw(x, y,width,height);
			}
		}
		else
		{
			LightManager.eraseBlend((Image) render);
			if (width == -1 ||  height == -1)
			{
				if (object.isLeft())
					((Image) render2).draw(x, y);
				else
					((Image) render).draw(x, y);
			}
			else
			{
				if (object.isLeft())
					((Image) render2).draw(x, y,width,height);
				else
					((Image) render).draw(x, y,width,height);
			}
		}
	}

	@Override
	public void update(int delta) {
		//nothing to update
	}
	
}
